/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admintool.imp03_data;

import java.util.ArrayList;

import admintool.AdminToolView;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Administrator
 */
public class IMP03_Tip {
    
    private class Tip{

        private int tipID = -1;
        private int stageID = -1;
        private int costs = -1;
        private String text = "";
        
        public Tip(int tipID, int stageID, int costs, String text) {
            this.tipID = tipID;
            this.stageID = stageID;
            this.costs = costs;
            this.text = text;
        }

        public int getCosts() {
            return costs;
        }

        public int getStageID() {
            return stageID;
        }

        public String getText() {
            return text;
        }

        public int getTipID() {
            return tipID;
        }
        
        
    }
    
    public static IMP03_Tip getEmptyTipObject(){
        return new IMP03_Tip(-1, -1, -1, AdminToolView.EMPTY);
    }
    
    public static ArrayList<IMP03_Tip> getAllAvailableTipsFromDB(boolean reload){
        
        PreparedStatement ps = null;
        ResultSet rs = null;
        
        try {
            if(reload == true || tips.isEmpty()){
                tips.clear();
                ps = AdminToolView.getDBConnection().prepareStatement("SELECT TipID, StageID, Costs, Text FROM tip");
                rs = ps.executeQuery();
                while(rs.next()){
                    tips.add(new IMP03_Tip(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getString(4)));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(rs != null){
                    rs.close();
                }
                if(ps != null){
                    ps.close();
                }
            } catch (Exception e) {
            }
        }
        
        return tips;
    }
        
    
    private static ArrayList<IMP03_Tip> tips = new ArrayList<IMP03_Tip>();
    private Tip tip = null;
    
    /**
     * 
     * @param messageID
     * @param candidateID
     * @param name
     * @param subject
     * @param content
     */
    public IMP03_Tip(int tipID, int stageID, int costs, String text ) {
        this.tip = new Tip(tipID, stageID, costs, text);
    }

    @Override
    public String toString() {
//        String tmpTipText = tip.getText();
//        
//        if(tmpTipText.length() > 20){
//            tmpTipText = tmpTipText.substring(0, 20) + "...";
//        }
        
        return tip.getText();
    }
    
    public int getStageID(){
        return tip.getStageID();
    }
    
    public int getCosts(){
        return tip.getCosts();
    }
        
    public String getTipText(){
        return tip.getText();
    }
    
    public int getTipID(){
        return tip.getTipID();
    }    
}
